<?php

  function RemoveBOM($s)
  {
      $charset = array();
      $charset[1] = substr($s, 0, 1);
      $charset[2] = substr($s, 1, 1);
      $charset[3] = substr($s, 2, 1);
      if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
          $s = substr($s, 3);
      }
      $s = preg_replace('/[\r\n]+/',"\n\n",$s);
      return $s;
  }

  $strAdd = trim(file_get_contents("addT.txt"));

  $strDel = trim(file_get_contents("badT.txt"));

  $strAdd = RemoveBOM($strAdd);

  $strDel = RemoveBOM($strDel);

  $addList = array_unique(explode("\n\n", $strAdd));

  $delList = array_unique(explode("\n\n", $strDel));

  $newList = array_diff($delList, $addList);

  file_put_contents("addT.txt", implode("\r\n\r\n", $addList));

  file_put_contents("badT.txt", implode("\r\n\r\n", $newList));

  echo __LINE__ . ":<br />\n";
  var_dump($addList);
  echo "<br />";
  echo __LINE__ . ":<br />\n";
  var_dump($delList);
  echo "<br />";
  echo __LINE__ . ":<br />\n";
  var_dump($newList);
  echo "<br />";
  die();
?>